package com.bingxue.edu.teacher.service;

import com.bingxue.edu.common.enums.EnrollmentStatusEnum;
import com.bingxue.edu.framework.common.util.ValidationUtils;
import com.bingxue.edu.management.education.model.query.EnrollClassQuery;
import com.bingxue.edu.management.education.model.resp.EnrollClassResp;
import com.bingxue.edu.management.education.model.resp.EnrollPermissionResp;
import com.bingxue.edu.management.education.service.EnrollPermissionService;
import com.bingxue.edu.management.education.service.EnrollmentService;
import com.bingxue.edu.management.education.service.StudentService;
import com.bingxue.edu.teacher.model.resp.TeacherStudentDetailResp;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

@Slf4j
@Service
@RequiredArgsConstructor
public class TeacherClassStudentService {

    private final StudentService studentService;
    private final EnrollPermissionService enrollPermissionService;
    private final EnrollmentService enrollmentService;


    public TeacherStudentDetailResp getStudentDetail(String studentId) {
        TeacherStudentDetailResp detail = studentService.getMapper().selectOneByIdAs(studentId, TeacherStudentDetailResp.class);
        ValidationUtils.throwIfNull(detail, "学生信息不存在");
        // 获取学生就读班级详情信息
//        List<String> classIds = classStudentService.getStudentClassIdByStudentId(studentId);
//        QueryWrapper queryWrapper = classInfoService.buildClassInfoQueryWrapper();
//        queryWrapper.where(CLASS_INFO.ID.in(classIds)).orderBy(CLASS_INFO.CREATE_TIME.desc());
//        List<ClassDetailResp> classInfoList = classInfoService.getMapper().selectListByQueryAs(queryWrapper, ClassDetailResp.class);
//        detail.setEnrollClassList(classInfoList);

        EnrollClassQuery enrollClassQuery = new EnrollClassQuery();
        enrollClassQuery.setStudentId(studentId);
        enrollClassQuery.setEnrollStatus(EnrollmentStatusEnum.NORMAL);
        List<EnrollClassResp> enrollClassList = enrollmentService.getEnrollClassList(enrollClassQuery);
        detail.setEnrollClassList(enrollClassList);
        // 获取学生选课权限信息
        List<EnrollPermissionResp> permissionList = enrollPermissionService.getPermissionListByStudentId(studentId);
        detail.setPermissionList(permissionList);

        return detail;
    }
}
